package com.godofgamblers.hotelmanagementsystem.mapper;

import com.godofgamblers.hotelmanagementsystem.pojo.Cart;
import com.godofgamblers.hotelmanagementsystem.pojo.Room_Type;
import com.godofgamblers.hotelmanagementsystem.pojo.User;
import com.godofgamblers.hotelmanagementsystem.pojo.User_Level;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author wzx
 * @date 2019/10/12 - 9:29
 * 购物车类的mapper
 */
public interface CartMapper {
    //选择一类房间加入购物车（参数：用户id,房间类型id，计划入住时间，计划退房时间）
    @Insert("insert into selected_cart(user_id,room_type_id,plan_stay_time,plan_leave_time) values(#{user_id},#{room_type_id},#{plan_stay_time},#{plan_leave_time})")
    public void addCart(Cart cart);

    //在购物车中点击移除按钮，删除某一行数据(参数：删除那一行的id(cart_id))
    @Update("update selected_cart set flag = 0 where cart_id = #{cart_id} and flag = 1")
    public void deleteCart(Integer cart_id);


    //用户登陆成功后点击自己的购物车查询属于自己的购物车（参数：用户id）返回一个集合装有多个项目
    @Select("select * from selected_cart where user_id = #{user_id} and flag = 1 ")
    public List<Cart> findMyCart(User user);

    //根据room_type_id去房间类型表找到对应房间的名字（参数:room_type_id）
    @Select("select * from room_type where room_type_id = #{room_type_id} and flag = 1")
    public Room_Type findRoomByRoomTypeId(Integer room_type_id);

    //根据用户的id去查询该用户的会员级别以及享受的折扣
    @Select("select * from user_level where (#{user_credit}>level_min_credit OR #{user_credit}=level_min_credit) AND (#{user_credit}<level_max_credit OR #{user_credit}=level_max_credit) and flag = 1 ")
    public User_Level findUserLevel(User user);

    //购物车当中修改入住时间和离店时间
    @Update("update selected_cart set play_stay_time = #{play_stay_time},play_leave_time = #{play_leave_time} where cart_id = #{cart_id} and flag = 1")
    public void updateCart(Cart cart);

    //通过cart_id,查询对应的房间类型id
    @Select("select * from selected_cart where cart_id = #{cart_id} and user_id = #{user_id} and flag = 1 ")
    public Cart findRoomTypeID(Map map);

    //传入cart_id，将对应的项目删除
    @Update("update selected_cart set flag = 0 where cart_id = #{cart_id}")
    public void deleteSomeCart(Integer cart_id);

}
